﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RPGXEngine.Networking;
using Microsoft.Xna.Framework;

namespace RPGX.Network
{
    public static class NetworkMessageProcessor
    {
        #region Public Methods

        public static void Process(NetworkMessage message)
        {
            if (message == null)
                throw new ArgumentNullException("message");

            switch (message.Type)
            {
                case MessageTypes.ConnectToServer:
                    break;
                case MessageTypes.ConnectToClient:
                    {
                        NetworkMessageProcessor.ConnectToClient(message as NetworkMessage_ConnectToClient);
                        break;
                    }
                case MessageTypes.NewClientConnected:
                    {
                        NetworkMessageProcessor.NewClientConnected(message as NetworkMessage_NewClientConnected);
                        break;
                    }
                case MessageTypes.ClientDisconnected:
                    {
                        NetworkMessageProcessor.ClientDisconnected(message as NetworkMessage_ClientDisconnected);
                        break;
                    }
                default:
                    throw new InvalidOperationException(String.Format("Unknown NetworkMessageType: {0}",
                        message.Type));
            }
        }

        #endregion

        #region Message Methods

        private static void ConnectToClient(NetworkMessage_ConnectToClient message)
        {
            Game1.Instance.GameClient.CurrentPlayerCount = message.CurrentClientCount;

            Game1.Instance.HUD.Announcements.Add(String.Format("We have {0} players now!!! ConnectToClient", Game1.Instance.GameClient.CurrentPlayerCount));
        }

        private static void NewClientConnected(NetworkMessage_NewClientConnected message)
        {
            Game1.Instance.GameClient.CurrentPlayerCount = message.CurrentPlayerCount;

            Game1.Instance.HUD.Announcements.Add(String.Format("We have {0} players now!!! NewClientConnected", Game1.Instance.GameClient.CurrentPlayerCount));
        }

        private static void ClientDisconnected(NetworkMessage_ClientDisconnected message)
        {
            Game1.Instance.HUD.Announcements.Add(String.Format("We have {0} players now!!! ClientDisconnected", Game1.Instance.GameClient.CurrentPlayerCount));
        }

        #endregion
    }
}
